#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;

class Apple
{
public:
    string id = "";
    int weight = 0;
    int diameter = 0;
    Apple();
    Apple(string, int, int);
    void print_fun(); // 按格式输出id， weight， diameter；
    ~Apple();
};

Apple::Apple()
{
}
Apple::~Apple()
{
}

Apple::Apple(const string s, const int weight, const int diameter) // 构造函数；
{
    this->id = s;
    this->weight = weight;
    this->diameter = diameter;
}

void Apple::print_fun()
{
    cout << this->id << " ";
    cout << this->weight << " ";
    cout << this->diameter << endl;
}


int re_Apple(const int n, const string s, vector<Apple>* A) // 根据苹果id寻找对象并返回；
{
    for (int i = 0; i < n; i++)
    {
        if (s == ((*A)[i].id))
        {
            return i;
        }
    }
}

int main()
{
    int N = 0;
    cin >> N;
    map<int, string> Map;
    vector<Apple> List;
    int basket = 0;
    string s = "";
    int w = 0;
    int d = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> basket;
        cin >> s;
        cin >> w >> d;
        List.push_back(Apple(s, w, d)); // 储存Apple对象；         

        // 记录当前筐的最大重量的（苹果的id）；
        if (Map.find(basket) == Map.end()) // 没有此篮筐；
        {
            Map[basket] = s;
        }
        else // 此篮筐存在；
        {
            if (w > List[re_Apple(N , Map[basket], &List)].weight) // 保留较大重量的（苹果的id）；
            {
                Map[basket] = s;
            }
        }
    }
    map<int, string>::iterator iter;
    for (iter = Map.begin(); iter != Map.end(); iter++)
    {
        cout << iter->first << " "; // 先打印篮筐编号；
        List[re_Apple(N, iter->second, &List)].print_fun();
    }
    return 0;
}
